package com.ting.test.algorithms.大厂刷题班;

import com.ting.test.algorithms.二叉树.TreeNode;

/**
 * 验证二插搜索树
 * 特征
 * 左子树的节点一定小于右子树
 */
public class 验证二插搜索树 {

    public static void main(String[] args) {
        TreeNode node = new TreeNode(3);
        boolean es = process(node);
    }

    private static boolean process(TreeNode node) {
        if (node == null) {
            return true;
        }
        boolean flag = node.getLeft().getVal() < node.getVal();
        flag = flag && node.getRight().getVal() > node.getVal();
        flag = flag && process(node.getLeft());
        flag = flag && process(node.getRight());
        return flag;
    }
}
